package net.hn.hnms.biz.process.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.process.domain.ShiftReporting;
import net.hn.hnms.biz.process.domain.StandardProcess;
import net.hn.hnms.biz.process.domain.vo.ShiftReportingVo;
import net.hn.hnms.biz.process.domain.vo.StandardProcessVo;
import net.hn.hnms.biz.process.mapper.StandardProcessMapper;
import net.hn.hnms.biz.process.service.StandardProcessService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@Api(value = "岗位标准化作业流程控制器", tags = {"岗位标准化作业流程控制器"})
@RestController
@RequestMapping("/standardProcess")
public class StandardProcessController extends BaseController {

    @Resource
    private StandardProcessService standardProcessService;

    @ApiOperation("新增")
    @SaCheckPermission("process:standardProcess:add")
    @PostMapping("/add")
    @Log(title = "新增岗位标准化作业流程", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody StandardProcess standardProcess) {
        return toAjax(standardProcessService.insert(standardProcess));
    }

    @ApiOperation("删除")
    @SaCheckPermission("process:standardProcess:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("delete")
    @Log(title = "删除岗位标准化作业流程", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        standardProcessService.deleteBatch(idList);
        return R.ok();
    }


    @ApiOperation("修改")
    @SaCheckPermission("process:standardProcess:update")
    @PutMapping("/update")
    @Log(title = "修改岗位标准化作业流程", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody StandardProcess standardProcess) {
        standardProcessService.updateById(standardProcess);
        return R.ok();
    }

    @ApiOperation("分页列表")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<StandardProcessVo>> page(StandardProcessVo standardProcessVo, PageQuery pageQuery) {
        return R.ok(standardProcessService.selectPageList(standardProcessVo, pageQuery));
    }


    @ApiOperation("获取详情")
    @GetMapping("/{id}")
    public R<StandardProcessVo> detail(@PathVariable("id") String id) {
        return R.ok(standardProcessService.selectDetailById(id));
    }

}
